package cumeo89.chii.client.entry.renderer;

import static cumeo89.chii.client.entry.Constants.*;

import com.google.gwt.xml.client.Attr;
import com.google.gwt.xml.client.Element;
import com.google.gwt.xml.client.Node;

import cumeo89.chii.client.entry.AbstractRenderer;
import cumeo89.chii.client.ui.ExtendedPanel;
import cumeo89.chii.client.ui.SeperatedNamedPanel;
import cumeo89.chii.client.util.XMLUtil;

public class ItemRenderer extends AbstractRenderer {

	public ItemRenderer() {
		SeperatedNamedPanel panel = new SeperatedNamedPanel("span", ":&nbsp;",
				new String[] { A_LANG, "content" });
		panel.setStyleName("item");
		initWidget(panel);
	}

	protected ExtendedPanel getChildContainer() {
		return null;
	}

	@Override
	public Node getAboveNode(Node child) {
		if (XMLUtil.hasTag(getRenderedNode().getPreviousSibling(), E_ITEM)) {
			return ((Element) getRenderedNode().getPreviousSibling())
					.getAttributeNode(((Attr) child).getName());
		}
		return null;
	}

	@Override
	public Node getBottomNode(Node child) {
		if (XMLUtil.hasTag(getRenderedNode().getNextSibling(), E_ITEM)) {
			return ((Element) getRenderedNode().getNextSibling())
					.getAttributeNode(((Attr) child).getName());
		}
		return null;
	}

}
